<template>
  <input
    class="lx-input-file"
    type="file"
    :multiple="multiple"
    :accept="accept"
    @change="onChange"
  />
</template>
<script>
export default {
  name: 'LxUpload',
  props: {
    multiple: {
      type: Boolean,
      default: false,
    }, // 可以接受多个文件上传
    accept: {
      type: String,
      default: '',
    }, // 支持的文件类型,逗号拼接字符串
  },
  data() {
    return {}
  },
  methods: {
    onChange(e) {
      const file = this.multiple ? e.target.files : e.target.files[0]
      this.$emit('change', file)
    },
  },
}
</script>
<style lang="scss" scoped>
.lx-input-file {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 1;
}
</style>
